<template>
  <div>
    <Card class="smart-query-card">
      <!------ 查询条件第一行 begin------->
      <Row class="smart-query-form-row" style="display:flex;flex-wrap:wrap;line-height:45px;margin-top:-8px">
        <div>
          任务名称 :
          <Input placeholder="请输入任务名称" style="width:180px;margin-right:10px" v-model="queryForm.name" />
        </div>
        <div>
          车辆编号 :
          <Input placeholder="请输入车辆编号" style="width:180px;margin-right:10px" v-model="queryForm.vehicleName" />
        </div>
        <div>
          <span>
            创建时间:
            <DatePicker placeholder="选择创建日期范围" split-panels style="width: 200px" type="daterange"
              v-model="queryForm.createTimeRange" :open="dateShow"></DatePicker>
          </span>
        </div>
        <div>
          <Button @click="queryList" icon="ios-search" type="primary">查询</Button>
          <Button @click="resetQueryList" icon="md-refresh" type="default" class="marginLeft10">重置</Button>
          <Button :loading="batchExportBtnLoading" @click="batchExport" class="marginLeft10" icon="ios-download-outline"
            type="primary">导出</Button>
          <Button @click="showBatchDeleteModal" class="marginLeft10" icon="ios-trash-outline" type="error">删除</Button>
        </div>
      </Row>
      <!------ 查询条件第一行 begin------->
    </Card>
    <Card class="warp-card" style="margin-bottom:20px">

      <Table :columns="mainTable.columnArray" height="388" :data="mainTable.data" :loading="mainTable.loading"
        :border="false" highlight-row ref="mainTable" @on-row-click="onRowClick" size="large">
        <template slot-scope="{ row, index }" slot="imageUrl">
          <img width="40" height="40" v-if="index % 2 === 0" src="http://q8deiydpv.bkt.clouddn.com/image/peony1.jpg" />
          <img v-if="index % 2 === 1" width="40" height="40" src="http://q8deiydpv.bkt.clouddn.com/image/peony2.jpg" />
        </template>
      </Table>
      <div class="com-query-page">
        <Page :current="queryForm.pageNum" :page-size="queryForm.pageSize" :page-size-opts="mainTablePage.pageSizeOps"
          :total="mainTablePage.total" @on-change="changeMainTablePagePageNum"
          @on-page-size-change="changeMainTablePagePageSize" class="smart-query-table-page page-bottom" show-elevator
          show-sizer show-total />
      </div>
    </Card>
    <Form ref="form" :rules="formValidate" :model="form" label-position="top">
      <Row wrap :gutter="24">
        <Col :lg="24" :md="24" :xs="24" :sm="24">
        <HomeCard title="任务参数">
          <div class="content-box">
            <Row :gutter="24">
              <Col :lg="12" :xs="12" :sm="12">
              <FormItem label="名称" prop="name">
                <Input v-model="form.name" />
              </FormItem>
              <FormItem prop="vehicleId">
                <Select clearable ref="VehicleListForm" placeholder="选择车辆" v-model="form.vehicleId"
                  @on-change="vehicleShowAddModal" @on-clear="cleanVehicle">
                  <Option :value="'VehicleListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.vehicle" :key="it.id">{{ it.sn }}</Option>
                </Select>
              </FormItem>
              </Col>
              <Col :lg="12" :xs="12" :sm="12">
              <FormItem label="说明" prop="explain">
                <Input v-model="form.explain" maxlength="150" show-word-limit type="textarea" :rows="4"
                  style="width: 100%" />
              </FormItem>
              </Col>
            </Row>
          </div>
        </HomeCard>
        </Col>
      </Row>
      <Row wrap class="row-sty">
        <Col :lg="12" :md="24" :xs="24" :sm="24">
        <HomeCard title="整车参数">
          <div class="content-box">
            <Row :gutter="24">
              <Col :lg="24" :xs="24" :sm="24">
              <FormItem prop="bodyId">
                <Select clearable ref="BodyListForm" placeholder="选择车身" v-model="form.bodyId"
                  @on-change="bodyShowAddModal" @on-clear="cleanBody">
                  <Option :value="'BodyListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.body" :key="it.id">{{ it.sn }}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row :gutter="24">
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem label="质量" prop="weight">
                <Input type="number" v-model.number="form.weight" required><template #append>
                  <span>kg</span>
                </template></Input>
              </FormItem>
              </Col>
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem label="迎风面积" prop="windwardArea">
                <Input type="number" v-model.number="form.windwardArea" required><template #append>
                  <span>m²</span>
                </template></Input>
              </FormItem>
              </Col>
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem label="风阻系数" prop="dragCoefficient">
                <Input type="number" v-model.number="form.dragCoefficient" required />
              </FormItem>
              </Col>
            </Row>
          </div>
        </HomeCard>
        </Col>
        <Col :lg="12" :md="24" :xs="24" :sm="24">
        <HomeCard title="动力参数">
          <div class="content-box">
            <Row :gutter="24">
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem prop="engineId">
                <Select clearable ref="EngineListForm" placeholder="选择动力源" v-model="form.engineId"
                  @on-change="engineShowAddModal" @on-clear="cleanEngine">
                  <Option :value="'EngineListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.engine" :key="it.id">{{ it.sn }}</Option>
                </Select>
              </FormItem>
              </Col>
              <Col :lg="16" :xs="16" :sm="16">
              <RadioGroup @on-change="engineTypeChange" v-model="form.engineType">
                <Radio label="最大扭矩点">
                </Radio>
                <Radio label="最大功率点">
                </Radio>
                <Radio label="最大转速">
                </Radio>
                <Radio label="怠速点">
                </Radio>
              </RadioGroup>
              </Col>
            </Row>
            <Row :gutter="24">
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem label="转速" prop="engineSpeed">
                <Input type="number" v-model.number="form.engineSpeed" required><template #append>
                  <span>rpm</span>
                </template></Input>
              </FormItem>
              </Col>
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem label="扭矩" prop="engineTorque">
                <Input type="number" v-model.number="form.engineTorque" required><template #append>
                  <span>Nm</span>
                </template></Input>
              </FormItem>
              </Col>
              <Col :lg="8" :xs="8" :sm="8">
              <FormItem label="功率" prop="enginePower">
                <Input type="number" v-model.number="form.enginePower" required><template #append>
                  <span>kW</span>
                </template></Input>
              </FormItem>
              </Col>
            </Row>
          </div>
        </HomeCard>
        </Col>
      </Row>
      <Row wrap class="row-sty">
        <Col :lg="12" :md="24" :xs="24" :sm="24">
        <HomeCard title="传动参数">
          <div class="content-box">
            <Row :gutter="24">
              <Col :lg="9" :xs="9" :sm="9">
              <FormItem label="变速箱" prop="generatorId">
                <Select clearable ref="GearboxListForm" placeholder="选择变速箱" v-model="form.generatorId"
                  @on-change="gearboxShowAddModal" @on-clear="cleanGearbox">
                  <Option :value="'GearboxListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.gearbox" :key="it.id">{{ it.sn }}</Option>
                </Select>
              </FormItem>
              </Col>
              <Col :lg="5" :xs="5" :sm="5">
              <FormItem label="挡位" prop="gearboxGear">
                <Select clearable v-model="form.gearboxGear" @on-change="selectGear">
                  <Option :value="index" v-for="index  in gearboxGear" :key="index">{{ index }}档</Option>
                </Select>
              </FormItem>
              </Col>
              <Col :lg="5" :xs="5" :sm="5">
              <FormItem label="速比" prop="gearboxSpeedRatio">
                <InputNumber type="number" :precision="2" v-model.number="form.gearboxSpeedRatio" required />
              </FormItem>
              </Col>
              <Col :lg="5" :xs="5" :sm="5">
              <FormItem label="效率" prop="gearboxEfficiency">
                <InputNumber type="number" :formatter="value => `${value}%`" :precision="2"
                  v-model.number="form.gearboxEfficiency" required />
              </FormItem>
              </Col>
            </Row>
            <Row :gutter="24">
              <Col :lg="9" :md="9" :xs="9" :sm="9">
              <FormItem label="驱动桥" prop="transaxleId">
                <Select clearable ref="TransaxleListForm" placeholder="选择驱动桥" v-model="form.transaxleId"
                  @on-change="transaxleShowAddModal" @on-clear="cleanTransaxle">
                  <Option :value="'TransaxleListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.transaxle" :key="it.id">{{ it.sn }}
                  </Option>
                </Select>
              </FormItem>
              </Col>
              <!-- <Col :lg="5" :md="24" :xs="24" :sm="24">
                <FormItem label="挡位" prop="transaxleGear">
                  <Select clearable v-model="form.transaxleGear">
                    <Option :value="index" v-for="index  in transaxleGear">{{ index }}档</Option>
                  </Select>
                </FormItem>
              </Col> -->
              <Col :lg="5" :md="5" :xs="5" :sm="5">
              <FormItem label="速比" prop="transaxleSpeedRatio">
                <Input type="number" v-model.number="form.transaxleSpeedRatio" required />
              </FormItem>
              </Col>
              <Col :lg="5" :md="5" :xs="5" :sm="5">
              <FormItem label="效率" prop="transaxleEfficiency">
                <InputNumber type="number" :formatter="value => `${value}%`" :precision="2"
                  v-model.number="form.transaxleEfficiency" required />
              </FormItem>
              </Col>
            </Row>
          </div>
        </HomeCard>
        </Col>
        <Col :lg="8" :md="16" :xs="16">
        <HomeCard title="路面参数">
          <div class="content-box">
            <Row :gutter="24">
              <Col :lg="24" :md="24" :xs="24" :sm="24">
              <FormItem label="路面" prop="roadId">
                <Select clearable ref="RoadListForm" v-model="form.roadId" @on-change="roadShowAddModal"
                  @on-clear="cleanRoad">
                  <Option :value="'RoadListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.road" :key="it.id">{{ it.name }}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row :gutter="24">
              <Col :lg="12" :md="12" :xs="12" :sm="12">
              <FormItem label="滚动系数" prop="rollingResistanceCoefficient">
                <Input type="number" v-model.number="form.rollingResistanceCoefficient" required />
              </FormItem>
              </Col>
              <Col :lg="12" :md="12" :xs="12" :sm="12">
              <FormItem label="附着系数" prop="adhesionCoefficient">
                <Input type="number" v-model.number="form.adhesionCoefficient" required />
              </FormItem>
              </Col>
            </Row>
          </div>
        </HomeCard>
        </Col>
        <Col :lg="4" :md="8" :xs="8">
        <HomeCard title="车轮参数">
          <div class="content-box">
            <Row :gutter="24">
              <Col :lg="24" :md="24" :xs="24" :sm="24">
              <FormItem label="车轮" prop="wheelId">
                <Select clearable ref="WheelListForm" v-model="form.wheelId" @on-change="wheelShowAddModal"
                  @on-clear="cleanWheel">
                  <Option :value="'WheelListForm'">新建</Option>
                  <Option :value="it.id" v-for="it in dataArray.wheel" :key="it.id">{{ it.sn }}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row :gutter="24">
              <Col :lg="24" :md="24" :xs="24" :sm="24">
              <FormItem label="车轮半径" prop="dynamicRollingRadius">
                <Input type="number" v-model.number="form.dynamicRollingRadius" required><template #append>
                  <span>m</span>
                </template></Input>
              </FormItem>
              </Col>
            </Row>
          </div>
        </HomeCard>
        </Col>
      </Row>
    </Form>
    <HomeCard title="">
      <Row wrap class="row-sty" style="width:100%">
        <Col :lg="3" :md="24" :xs="24">
        <div class="content-box button-box-top">
          <div class="button_box">
            <Row wrap class="row-sty">
              <Col :lg="24" :md="8" :xs="8">
              <Button size="large" icon="ios-open-outline" class="button_flex" @click="impotEvent">导入</Button>
              </Col>
              <Col :lg="24" :md="8" :xs="8">
              <Button size="large" icon="ios-create-outline" class="button_flex" @click="compute">计算</Button>
              </Col>
              <Col :lg="24" :md="8" :xs="8">
              <Button size="large" icon="ios-paper-outline" class="button_flex" @click="save">保存</Button>
              </Col>
            </Row>
          </div>
        </div>
        </Col>
        <Col :lg="21" :md="24" :xs="24" :sm="24">
        <div class="content-box">
          <div class="box">
            <div class="easy-computer2">
              <Form ref="form1" :model="form" label-position="top">
                <Row :gutter="24" class-name="result-row">
                  <Col :lg="14" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="风阻" prop="windResistance">
                    <Input v-model.number="result.windResistance" disabled class="result-input">
                    <template #append>
                      <span>N</span>
                    </template></Input>
                  </FormItem>
                  </Col>
                </Row>
                <Row :gutter="24" class-name="result-row">
                  <Col :lg="20" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="车速" prop="speed">
                    <Input v-model.number="result.speed" disabled class="result-input">
                    <template #append>
                      <span>km/h</span>
                    </template></Input>
                  </FormItem>
                  </Col>
                </Row>
                <Row :gutter="24" class-name="result-row">
                  <Col :lg="3" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="动力因数" prop="dynamicFactor">
                    <Input v-model.number="result.dynamicFactor" disabled class="result-input" />
                  </FormItem>
                  </Col>
                </Row>
                <Row :gutter="24" class-name="result-row">
                  <Col :lg="18" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="滚阻" prop="rollResistance">
                    <Input v-model.number="result.rollResistance" disabled class="result-input">
                    <template #append>
                      <span>N</span>
                    </template></Input>
                  </FormItem>
                  </Col>
                </Row>
                <Row :gutter="24" class-name="result-row">
                  <Col :lg="13" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="坡道阻力" prop="rampResistance">
                    <Input v-model.number="result.rampResistance" disabled class="result-input">
                    <template #append>
                      <span>N</span>
                    </template></Input>
                  </FormItem>
                  </Col>
                </Row>
                <Row :gutter="24" class-name="result-row" :style="screenWidth >= 992 ? 'margin-top:-23px' : ''">
                  <Col :lg="10" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="牵引力" prop="drive">
                    <Input v-model.number="result.drive" disabled class="result-input">
                    <template #append>
                      <span>N</span>
                    </template></Input>
                  </FormItem>
                  </Col>
                </Row>
                <Row :gutter="24" class-name="result-row last-row">
                  <Col :lg="3" :md="24" :xs="24" :sm="24" class="col-sty">
                  <FormItem label="坡度" prop="drive">
                    <Input type="number" v-model.number="form.slope" class="result-input">
                    <template #append>
                      <span>%</span>
                    </template></Input>
                  </FormItem>
                  </Col>
                </Row>
              </Form>
            </div>
          </div>
        </div>
        </Col>
      </Row>
    </HomeCard>

    <Modal :footer-hide="true" :title="saveModal.title" v-model="saveModal.show" @on-ok="saveFormSubmit"
      @on-cancel="saveFormClose" :width="modalWidth">
      <VehicleListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(1)"
        v-if="modalFormType == 'VehicleListForm'" ref="child" />
      <BodyListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(2)"
        v-if="modalFormType == 'BodyListForm'" ref="child" />
      <RoadListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(3)"
        v-if="modalFormType == 'RoadListForm'" ref="child" />
      <GearboxListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(4)"
        v-if="modalFormType == 'GearboxListForm'" ref="child" />
      <EngineListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(5)"
        v-if="modalFormType == 'EngineListForm'" ref="child" />
      <WheelListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(6)"
        v-if="modalFormType == 'WheelListForm'" ref="child" />
      <TransaxleListForm :isUpdate="false" @on-form-close="saveFormClose" @on-resetData="resetData(7)"
        v-if="modalFormType == 'TransaxleListForm'" ref="child" />
    </Modal>
    <!-------批量删除Modal begin------->
    <Modal title="批量删除" v-model="batchDeleteModal.show" width="450">
      <Form :label-width="80">
        <FormItem>
          <h3 class="error-color">确定要删除以下数据吗？</h3>
        </FormItem>
        <FormItem label="删除数据">
          <Card style="width:350px;height:250px;overflow-y:scroll;">
            <ul>
              <li v-for="item in mainTableSelectArray">
                <a href="#">{{ item.name }}</a>
              </li>
            </ul>
          </Card>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button @click="batchDeleteModal.show = false" size="small" type="default">取消</Button>
        <Button @click="batchDelete" size="small" type="primary">确定删除</Button>
      </div>
    </Modal>
    <vxe-table class="sortable-row-demo" ref="xTable" :data="exportData" highlight-hover-row show-overflow
      style="display:none" :export-config="{
        filename: filename(),
        type: 'cvs'
      }">
      <vxe-column :field="item.type" v-for="item in csvModel" :title="item.name" :key="item.type" width="120">
      </vxe-column>
    </vxe-table>
  </div>
</template>

<script>
import { dateTimeRangeConvert } from "@/lib/util";
import { easyComputeResultApi } from "@/api/easy-compute-result";
import { easyComputeModelApi } from "@/api/easy-compute-model";
import { vehicleApi } from "@/api/vehicle";
import { bodyApi } from "@/api/body";
import { engineApi } from "@/api/engine";
import { gearboxApi } from "@/api/gearbox";
import { roadApi } from "@/api/road";
import { environmentApi } from "@/api/environment";
// 驱动桥
import { driveshaftApi } from "@/api/driveshaft";
// 轮胎
import { wheelApi } from "@/api/wheel";
// 轮胎
import { transaxleApi } from "@/api/transaxle";
// 轮胎
import { gearboxSpeedApi } from "@/api/gearbox-speed";

import { PAGE_SIZE_OPTIONS } from "@/constants/table-page";
import HomeCard from "./components/card";
import BodyListForm from "../body/components/body-list-form"
import EngineListForm from "../engine/components/engine-list-form"
import GearboxListForm from "../gearbox/components/gearbox-list-form"
import RoadListForm from "../road/components/road-list-form"
import EnvironmentListForm from "../environment/components/environment-list-form"
import VehicleListForm from "../vehicle/components/vehicle-list-form"
import WheelListForm from "../wheel/components/wheel-list-form"
import DriveshaftListForm from "../driveshaft/components/driveshaft-list-form"
import TransaxleListForm from "../transaxle/components/transaxle-list-form"
import XLSX from "xlsx";
const PAGE_SIZE_INIT = 5;
export default {
  name: "EasyCompute",
  components: {
    HomeCard,
    BodyListForm,
    VehicleListForm,
    RoadListForm,
    GearboxListForm,
    EngineListForm,
    EnvironmentListForm,
    WheelListForm,
    DriveshaftListForm,
    TransaxleListForm
  },
  props: {},
  data() {
    return {
      modalWidth: 750,
      dateShow: false,
      gearboxGear: 7,
      transaxleGear: 7,
      oldModelName: "",
      mainTableSelectArray: [],
      batchExportBtnLoading: false,
      modalFormType: "",
      saveModal: {
        title: "新建",
        show: false,
      },
      /* -------------------------批量操作------------------------- */
      // 批量刪除彈出框
      batchDeleteModal: {
        show: false
      },
      // 表格
      mainTable: {
        // 加载中
        loading: false,
        // 表格数据
        data: [],
        // 表格列
        columnArray: [
          {
            type: "selection",
            width: 30,
            align: "center",
          },
          {
            title: "任务参数",
            align: "center",
            children: [
              {
                title: "任务名称",
                key: "name",
                tableColumn: "result.name",
                width: 150,
                tooltip: true,
              },
              {
                title: "整车编号",
                key: "vehicleSn",
                tableColumn: "result.vehicleSn",
                width: 150,
                tooltip: true,
              },
              {
                title: "说明",
                align: "center",
                key: "explain",
                width: 200,
                tooltip: true,
              },
            ]
          },
          {
            title: "整车参数",
            align: "center",
            children: [
              {
                title: "车身编号",
                key: "bodySn",
                tableColumn: "result.bodySn",
                width: 150,
                tooltip: true,
              },
              {
                title: '质量(kg)',
                key: 'weight',
                tableColumn: 't_easy_compute_model.weight',

                width: 150,
                tooltip: true,
              },
              {
                title: '迎风面积(m²)',
                key: 'windwardArea',
                tableColumn: 't_easy_compute_model.windward_area',

                width: 150,
                tooltip: true,
              },
              {
                title: '风阻系数',
                key: 'dragCoefficient',
                tableColumn: 't_easy_compute_model.drag_coefficient',

                width: 150,
                tooltip: true,
              },
            ]
          },
          {
            title: "动力参数",
            align: "center",
            children: [
              {
                title: "动力源",
                key: "engineSn",
                tableColumn: "result.engineSn",
                width: 150,
                tooltip: true,
              },
              {
                title: "动力类型",
                key: "engineType",
                tableColumn: "result.engineType",
                width: 150,
                tooltip: true,
              },
              {
                title: '转速(rpm)',
                key: 'engineSpeed',
                tableColumn: 't_easy_compute_model.engine_speed',

                width: 150,
                tooltip: true,
              },
              {
                title: '扭矩(Nm)',
                key: 'engineTorque',
                tableColumn: 't_easy_compute_model.engine_torque',

                width: 150,
                tooltip: true,
              },
              {
                title: '功率(kW)',
                key: 'enginePower',
                tableColumn: 't_easy_compute_model.engine_power',

                width: 150,
                tooltip: true,
              },
            ]
          },
          {
            title: "传动参数",
            align: "center",
            children: [
              {
                title: "变速箱",
                key: 'gearbox',
                children: [
                  {
                    title: '编号',
                    key: 'gearboxSn',
                    tableColumn: 't_easy_compute_model.gearbox',

                    width: 150,
                    tooltip: true,
                  },
                  {
                    title: '挡位',
                    key: 'gearboxGear',
                    tableColumn: 't_easy_compute_model.gearbox_gear',

                    width: 150,
                    tooltip: true,
                  },
                  {
                    title: '速比',
                    key: 'gearboxSpeedRatio',
                    tableColumn: 't_easy_compute_model.gearbox_speed_ratio',

                    width: 150,
                    tooltip: true,
                  },
                  {
                    title: '效率(%)',
                    key: 'gearboxEfficiency',
                    tableColumn: 't_easy_compute_model.gearbox_efficiency',

                    width: 150,
                    tooltip: true,
                  },
                ]
              },

              {
                title: "驱动桥",
                key: 'transaxle',
                children: [
                  {
                    title: "编号",
                    key: "transaxleSn",
                    tableColumn: "result.transaxle",
                    width: 150,
                    tooltip: true,
                  },
                  {
                    title: '速比',
                    key: 'transaxleSpeedRatio',
                    tableColumn: 't_easy_compute_model.drive_shaft_speed_ratio',

                    width: 150,
                    tooltip: true,
                  },
                  {
                    title: '效率(%)',
                    key: 'transaxleEfficiency',
                    tableColumn: 't_easy_compute_model.drive_shaft_efficiency',

                    width: 150,
                    tooltip: true,
                  },
                ]
              },

            ]
          },
          {
            title: "路面参数",
            align: "center",
            children: [
              {
                title: "路面名称",
                key: "roadSn",
                tableColumn: "result.road",
                width: 150,
                tooltip: true,
              },
              {
                title: '滚阻系数',
                key: 'rollingResistanceCoefficient',
                tableColumn: 't_easy_compute_model.rolling_resistance_coefficient',

                width: 150,
                tooltip: true,
              },
              {
                title: '附着系统',
                key: 'adhesionCoefficient',
                tableColumn: 't_easy_compute_model.adhesion_coefficient',

                width: 150,
                tooltip: true,
              },
            ]
          },
          {
            title: "车轮参数",
            align: "center",
            children: [
              {
                title: "轮胎编号",
                key: "wheelSn",
                tableColumn: "result.wheel",
                width: 150,
                tooltip: true,
              },
              {
                title: '轮胎半径(m)',
                key: 'dynamicRollingRadius',
                tableColumn: 't_easy_compute_model.dynamic_rolling_radius',

                width: 150,
                tooltip: true,
              },
            ]
          },
          {
            title: "模型计算结果",
            align: "center",
            children: [
              {
                title: '动力因数',
                key: 'dynamicFactor',
                tableColumn: 't_easy_compute_result.dynamic_factor',

                width: 150,
                tooltip: true,
              },
              {
                title: '风阻(N)',
                key: 'windResistance',
                tableColumn: 't_easy_compute_result.wind_resistance',
                width: 150,
                tooltip: true,
              },
              {
                title: '车速(km/h)',
                key: 'speed',
                tableColumn: 't_easy_compute_result.speed',
                width: 150,
                tooltip: true,
              },
              {
                title: '滚阻(N)',
                key: 'rollResistance',
                tableColumn: 't_easy_compute_result.roll_resistance',
                width: 150,
                tooltip: true,
              },
              {
                title: '坡道阻力(N)',
                key: 'rampResistance',
                tableColumn: 't_easy_compute_result.ramp_resistance',
                width: 150,
                tooltip: true,
              },
              {
                title: '牵引力(N)',
                key: 'drive',
                tableColumn: 't_easy_compute_result.drive',
                width: 150,
                tooltip: true,
              },
              {
                title: '坡度(%)',
                key: 'slope',
                tableColumn: 't_easy_compute_result.slope',
                width: 150,
                tooltip: true,
              },
            ]
          },
          // {
          //   title: '创建人',
          //   key: 'createUserName',
          //   tableColumn: 't_easy_compute_result.rear_axle_load',

          //   width: 150
          // },
          {
            title: '创建时间',
            key: 'createTime',
            tableColumn: 't_easy_compute_result.rear_axle_load',

            width: 150,
            tooltip: true,
          },
          {
            title: '最近修改时间',
            key: 'updateTime',
            tableColumn: 't_easy_compute_result.rear_axle_load',

            width: 150,
            tooltip: true,
          }, {
            title: '操作用户',
            key: 'updateUserName',
            tableColumn: 't_easy_compute_result.rear_axle_load',

            width: 150,
            tooltip: true,
          },
        ]
      },
      csvModel: [{
        name: "任务参数-任务名称",
        type: "name"
      },
      {
        name: "任务参数-整车编号",
        type: "vehicleSn"
      },
      {
        name: "任务参数-说明",
        type: "explain"
      },
      {
        name: "整车参数-车身",
        type: "bodySn"
      },

      {
        name: "整车参数-质量(kg)",
        type: "weight"
      },

      {
        name: "整车参数-迎风面积(m²)",
        type: "windwardArea"
      },

      {
        name: "整车参数-风阻系数",
        type: "dragCoefficient"
      },

      {
        name: "动力参数-动力源",
        type: "engineSn"
      },

      {
        name: "动力参数-动力类型",
        type: "engineType"
      },

      {
        name: "动力参数-转速(rpm)",
        type: "engineSpeed"
      },

      {
        name: "动力参数-扭矩(Nm)",
        type: "engineTorque"
      },

      {
        name: "动力参数-功率(kW)",
        type: "enginePower"
      },

      {
        name: "传动参数-变速箱-编号",
        type: "gearboxSn"
      },

      {
        name: "传动参数-变速箱-挡位",
        type: "gearboxGear"
      },

      {
        name: "传动参数-变速箱-速度比",
        type: "gearboxSpeedRatio"
      },

      {
        name: "传动参数-变速箱-效率(%)",
        type: "gearboxEfficiency"
      },

      {
        name: "传动参数-驱动桥-编号",
        type: "transaxleSn"
      },

      {
        name: "传动参数-驱动桥-速度比",
        type: "transaxleSpeedRatio"
      },

      {
        name: "传动参数-驱动桥-效率",
        type: "transaxleEfficiency"
      },


      {
        name: "路面-编号",
        type: "roadSn"
      },

      {
        name: "路面-滚阻系数",
        type: "rollingResistanceCoefficient"
      },

      {
        name: "路面-附着系统",
        type: "adhesionCoefficient"
      },

      {
        name: "轮胎-编号",
        type: "wheelSn"
      },

      {
        name: "轮胎-轮胎半径(m)",
        type: "dynamicRollingRadius"
      },


      {
        name: "模型计算结果-动力因数",
        type: "dynamicFactor"
      },

      {
        name: "模型计算结果-风阻(N)",
        type: "windResistance"
      },

      {
        name: "模型计算结果-车速(km/h)",
        type: "speed"
      },

      {
        name: "模型计算结果-滚阻(N)",
        type: "rollResistance"
      },

      {
        name: "模型计算结果-坡道阻力(N)",
        type: "rampResistance"
      },

      {
        name: "模型计算结果-牵引力(N)",
        type: "drive"
      },

      {
        name: "模型计算结果-坡度(%)",
        type: "slope"
      },


      {
        name: "创建时间", format: "yyyy-MM-dd HH:mm:ss",
        type: "createTime"
      },

      {
        name: "更新时间", format: "yyyy-MM-dd HH:mm:ss",
        type: "updateTime"
      },

      {
        name: "操作用户",
        type: "updateUserName"
      },],

      queryForm: {
        name: "",
        vehicleName: "",
        createTimeRange: ["", ""],
        pageNum: 1,
        pageSize: PAGE_SIZE_INIT,
        orders: []
      },
      // 表格分页
      mainTablePage: {
        total: 0,
        pageSizeOps: PAGE_SIZE_OPTIONS
      },
      form: {
        //编号
        sn: null,
        //名称
        name: null,
        //整车id
        vehicleId: null,
        //环境id
        environmentId: null,
        //路面id
        roadId: null,
        //车身id
        bodyId: null,
        //发动机id
        engineId: null,
        //变速箱id
        generatorId: null,
        //驱动桥id
        transaxleId: null,
        //轮胎id
        wheelId: null,
        //传动轴id
        driveShaftId: null,
        //质量
        weight: null,
        //迎风面积
        windwardArea: null,
        //风阻系数
        dragCoefficient: null,
        //发动机-类型
        engineType: "最大扭矩点",
        //转速
        engineSpeed: null,
        //转矩
        engineTorque: null,
        //功率
        enginePower: null,
        //变速箱-挡位
        gearboxGear: null,
        //变速箱-速度比
        gearboxSpeedRatio: null,
        //变速箱-效率
        gearboxEfficiency: null,
        //驱动桥-挡位
        transaxleGear: null,
        //驱动桥-速度比
        transaxleSpeedRatio: null,
        //驱动桥-效率
        transaxleEfficiency: null,
        //滚阻系数
        rollingResistanceCoefficient: null,
        //附着系统
        adhesionCoefficient: null,
        //轮胎半径
        dynamicRollingRadius: null,
        //坡度
        slope: null,
        //说明
        explain: null,
        //最近使用
        updateUser: null,
        //创建者
        createUser: null,
      },
      result: {
        //模型id
        modelId: null,
        //动力因数
        dynamicFactor: null,
        //风阻
        windResistance: null,
        //车速
        speed: null,
        //滚阻
        rollResistance: null,
        //坡道阻力
        rampResistance: null,
        //牵引力
        drive: null,
      },

      //表单验证
      formValidate: {
        //名称
        name: [{ required: true, message: '请输入名称', trigger: 'blur' }, {

          type: "string",
          min: 2,
          max: 20,
          message: "请输入2到20个字",
          trigger: "blur"

        }],
        //质量
        weight: [{ type: 'number', required: true, message: '请输入质量', trigger: 'blur' }],
        //迎风面积
        windwardArea: [{ type: 'number', required: true, message: '请输入迎风面积', trigger: 'blur' }],
        //风阻系数
        dragCoefficient: [{ type: 'number', required: true, message: '请输入风阻系数', trigger: 'blur' }],
        //转速
        engineSpeed: [{ type: 'number', required: true, message: '请输入转速', trigger: 'blur' }],
        //转矩
        engineTorque: [{ type: 'number', required: true, message: '请输入转矩', trigger: 'blur' }],
        //功率
        enginePower: [{ type: 'number', required: true, message: '请输入功率', trigger: 'blur' }],
        //变速箱-速度比
        gearboxSpeedRatio: [{ type: 'number', required: true, message: '请输入变速箱-速度比', trigger: 'blur' }],
        //变速箱-效率
        gearboxEfficiency: [{ type: 'number', required: true, message: '请输入变速箱-效率', trigger: 'blur' }],
        //驱动桥-速度比
        transaxleSpeedRatio: [{ type: 'number', required: true, message: '请输入驱动桥-速度比', trigger: 'blur' }],
        //驱动桥-效率
        transaxleEfficiency: [{ type: 'number', required: true, message: '请输入驱动桥-效率', trigger: 'blur' }],
        //滚阻系数
        rollingResistanceCoefficient: [{ type: 'number', required: true, message: '请输入滚阻系数', trigger: 'blur' }],
        //附着系统
        adhesionCoefficient: [{ type: 'number', required: true, message: '请输入附着系统', trigger: 'blur' }],
        //轮胎半径
        dynamicRollingRadius: [{ type: 'number', required: true, message: '请输入轮胎半径', trigger: 'blur' }],
      },
      dataArray: {
        vehicle: [],
        road: [],
        environment: [],
        body: [],
        engine: [],
        gearbox: [],
        driveshaft: [],
        wheel: [],
        transaxle: []
      },
      resultList: [],
      modal: [
        { key: "VehicleListForm", title: "整车", width: 750 },
        { key: "BodyListForm", title: "车身", width: 750 },
        { key: "GearboxListForm", title: "变速箱", width: 750 },
        { key: "TransaxleListForm", title: "驱动桥", width: 750 },
        { key: "EngineListForm", title: "发动机", width: 1000 },
        { key: "WheelListForm", title: "轮胎", width: 750 },
        { key: "RoadListForm", title: "路面", width: 500 }],
      engineType: {
        "最大扭矩点": ["speedAtMaxTorque", "torqueAtMaxTorque", "powerAtMaxTorque"],
        "最大功率点": ["speedAtMaxPower", "torqueAtMaxPower", "powerAtMaxPower"],
        "最大转速": ["speedAtMaxSpeed", "torqueAtMaxSpeed", "powerAtMaxSpeed"],
        "怠速点": ["speedAtIdleSpeed", "torqueAtIdleSpeed", "powerAtIdleSpeed"],
      },
      exportData: [],
      screenWidth: 0
    }
  },
  computed: {},
  watch: {},
  filters: {},
  created() {
    this.getDataArray();
    this.screenWidth = document.body.clientWidth;
  },
  mounted() {
    this.queryList();
    const that = this;
    window.onresize = () => {
      return (() => {
        window.screenWidth = document.body.clientWidth;
        console.log(this.screenWidth);
        that.screenWidth = window.screenWidth;
      })()
    }
  },
  beforeCreate() { },
  beforeMount() { },
  beforeUpdate() { },
  updated() { },
  beforeDestroy() { },
  destroyed() { },
  activated() { },
  methods: {
    cleanForm() {
      this.form = {
        //编号
        sn: null,
        //名称
        name: null,
        //整车id
        vehicleId: null,
        //环境id
        environmentId: null,
        //路面id
        roadId: null,
        //车身id
        bodyId: null,
        //发动机id
        engineId: null,
        //变速箱id
        generatorId: null,
        //驱动桥id
        transaxleId: null,
        //轮胎id
        wheelId: null,
        //传动轴id
        driveShaftId: null,
        //质量
        weight: null,
        //迎风面积
        windwardArea: null,
        //风阻系数
        dragCoefficient: null,
        //发动机-类型
        engineType: "最大扭矩点",
        //转速
        engineSpeed: null,
        //转矩
        engineTorque: null,
        //功率
        enginePower: null,
        //变速箱-挡位
        gearboxGear: null,
        //变速箱-速度比
        gearboxSpeedRatio: null,
        //变速箱-效率
        gearboxEfficiency: null,
        //驱动桥-挡位
        transaxleGear: null,
        //驱动桥-速度比
        transaxleSpeedRatio: null,
        //驱动桥-效率
        transaxleEfficiency: null,
        //滚阻系数
        rollingResistanceCoefficient: null,
        //附着系统
        adhesionCoefficient: null,
        //轮胎半径
        dynamicRollingRadius: null,
        //坡度
        slope: null,
        //说明
        explain: null,
        //最近使用
        updateUser: null,
        //创建者
        createUser: null,
      }

    },
    cleanResult() {
      this.result = {
        //模型id
        modelId: null,
        //动力因数
        dynamicFactor: null,
        //风阻
        windResistance: null,
        //车速
        speed: null,
        //滚阻
        rollResistance: null,
        //坡道阻力
        rampResistance: null,
        //牵引力
        drive: null,
      }
    },
    filename() {
      return (
        "简单计算模型任务列表" +
        new Date(+new Date() + 8 * 3600 * 1000)
          .toJSON()
          .substr(0, 19)
          .replace("T", "")
          .replaceAll("-", "")
          .replaceAll(":", "")
      );
    },
    //导入
    impotEvent() {
      try {
        this.$refs.xTable
          .readFile({
            types: ["xls", "xlsx", "csv"]
          })
          .then(params => {
            this.$Spin.show();
            this.cleanForm();
            this.cleanResult();
            const { files } = params;
            const fileReader = new FileReader();
            fileReader.onload = ev => {
              const data = ev.target.result;
              const workbook = XLSX.read(data, { type: "binary" });
              const csvData = XLSX.utils.sheet_to_csv(workbook.Sheets.Sheet1);
              const tableData = [];
              console.log("解析的输入：");
              // 解析数据csvData
              const rows = csvData.split("\n")
              rows[0] = rows[0].split(",");
              rows[1] = rows[1].split(",");
              rows[0].forEach((item, i) => {
                var pojo = rows[1][i];

                var model = this.csvModel.find(e => e.name == item)
                console.log(model)
                if (!model) {
                  return;
                }
                var type = model.type
                if (type.indexOf("Sn") == -1) {
                  if (this.form.hasOwnProperty(type)) {


                    if (type != "name" && type != "remark" && type != "explain" && type != "engineType") {
                      this.form[type] = parseFloat(pojo)
                    } else {
                      this.form[type] = pojo
                    }
                  }
                  if (this.result.hasOwnProperty(type)) {
                    this.result[type] = pojo
                  }
                } else {
                  switch (type) {
                    //整车
                    case "vehicleSn":
                      this.selectVehicleSn(pojo)
                      break;
                    //路面id
                    case "roadSn":
                      this.selectRoadSn(pojo)
                      break;
                    //车身id
                    case "bodySn":
                      this.selectBodySn(pojo)
                      break;
                    //变速箱id
                    case "gearboxSn":
                      this.selectGearboxSn(pojo)
                      break;
                    //发动机id
                    case "engineSn":
                      this.selectEngineSn(pojo)
                    //驱动桥id
                    case "transaxleSn":
                      this.selectTransaxleSn(pojo)
                      break;
                    //驱动桥id
                    case "wheelSn":
                      this.selectWheelSn(pojo)
                      break;
                    //路面id
                    case "roadSn":
                      this.selectRoadSn(pojo)
                      break;
                  }
                }
                console.log(this.form)
              })
              this.$refs["form"].validate()
            };
            fileReader.readAsBinaryString(files[0]);

            this.$Spin.hide();
            this.$Message.success("导入成功");

          });
      } catch (e) {
        this.$Message.success("导入失败");
      }
    },
    onRowClick(model, index) {
      for (var i in this.form) {
        this.form[i] = model[i];
      }
      for (var i in this.result) {
        this.result[i] = model[i];

      }
      this.oldModelName = model.name
    },
    // 查询
    convertQueryParam() {
      let createTimeArray = dateTimeRangeConvert(
        this.queryForm.createTimeRange
      );
      return {
        ...this.queryForm,
        createTimeBegin: createTimeArray[0],
        createTimeEnd: createTimeArray[1],
      };
    },
    async queryList() {
      this.mainTable.loading = true;
      try {
        let params = this.convertQueryParam();
        let result = await easyComputeModelApi.queryEasyComputeModel(params);
        this.mainTable.data = result.data.list;
        this.mainTablePage.total = result.data.total;
      } finally {
        this.mainTable.loading = false;
      }
    },
    //重置查询
    resetQueryList() {
      let pageSize = this.queryForm.pageSize;
      this.queryForm = {
        createTimeRange: ["", ""],
        updateTimeRange: ["", ""],
        pageNum: 1,
        pageSize: pageSize,
        orders: [],
        name: "",
        vehicleName: "",
      };
      this.queryList();
    },
    //修改页码
    changeMainTablePagePageNum(pageNum) {
      this.queryForm.pageNum = pageNum;
      this.queryList();
    },
    //修改页大小
    changeMainTablePagePageSize(pageSize) {
      this.queryForm.pageNum = 1;
      this.queryForm.pageSize = pageSize;
      this.queryList();
    },
    vehicleShowAddModal(e) { if ((e + '').indexOf("Form") === -1) this.selectVehicle(e); else this.showModal(e); },
    roadShowAddModal(e) { if ((e + '').indexOf("Form") === -1) this.selectRoad(e); else this.showModal(e); },
    gearboxShowAddModal(e) { if ((e + '').indexOf("Form") === -1) this.selectGearbox(e); else this.showModal(e); },
    engineShowAddModal(e) { if ((e + '').indexOf("Form") === -1) this.selectEngine(e); else this.showModal(e); },
    bodyShowAddModal(e) { if ((e + '').indexOf("Form") === -1) this.selectBody(e); else this.showModal(e); },
    wheelShowAddModal(e) { if ((e + '').indexOf("Form") === -1) this.selectWheel(e); else this.showModal(e); },
    transaxleShowAddModal(e) {
      if ((e + '').indexOf("Form") === -1)
        this.selectTransaxle(e);
      else this.showModal(e);
    },
    showModal(e) {
      this.$refs[e].clearSingleSelect();
      this.$emit("on-form-close");
      this.modalFormType = e;
      var item = this.modal.find(it => it.key == e);
      this.saveModal.title = "新增" + item.title;
      this.modalWidth = item.width;
      this.saveModal.show = true;
    },
    saveFormClose() {
      this.$refs.child.resetForm();
      this.saveModal.show = false;
    },
    saveFormSubmit() {
      this.getDataArray();
    },
    /*-------------------------批量操作 begin------------------------- */
    //显示批量删除弹窗
    showBatchDeleteModal() {
      if (!this.validateMainTableSelection()) {
        return;
      }
      this.batchDeleteModal.show = true;
    },
    //批量删除
    async batchDelete() {
      this.$Spin.show();
      await easyComputeModelApi.batchDeleteEasyComputeModel(
        this.mainTableSelectArray.map(e => e.id)
      );
      this.batchDeleteModal.show = false;
      this.$Message.success('刪除成功');
      this.$Spin.hide();
      this.queryList();
    },
    //清空选中
    clearMainTableSelection() {
      this.mainTableSelectArray = [];
    },
    //校验是否有选中
    validateMainTableSelection() {
      this.mainTableSelectArray = this.$refs.mainTable.getSelection();
      if (this.mainTableSelectArray.length < 1) {
        this.$Message.error('请选择至少一条数据');
        return false;
      }
      return true;
    },
    /*-------------------------批量操作 end------------------------- */
    changeIndexModel(data) {
      this.form = data.form;
      this.result = data.result;
    },
    async compute() {
      if (!this.form.name) {
        this.$Message.error("请输入名称");
        return;
      }

      this.$Spin.show();
      let res = await easyComputeModelApi.addEasyComputeModel(this.form);
      this.$Message.success(res.msg);
      if (res.code == 1) {
        this.result = res.data;
        let form = JSON.parse(JSON.stringify(this.form));
        let obj = {
          form: form,
          result: res.data
        };
        this.resultList.push(obj);
      }
      this.$Spin.hide();
    },
    async save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          var bool = this.oldModelName && this.oldModelName == this.form.name
          this.$Modal.confirm({
            title: bool ? '更新' : '新增',
            content: bool ? '是否更新当前数据' : '是否新增一条新数据',
            onOk: () => {

              this.$Spin.show();
              if (bool) {
                easyComputeModelApi.updateEasyComputeModel({ ...this.form, ...this.result }).then(res => {
                  this.$Message.success(res.msg);
                  this.queryList();
                  this.$Spin.hide();
                });
              } else {
                easyComputeModelApi.addEasyComputeModelAndResult({ ...this.form, ...this.result }).then(res => {
                  this.$Message.success(res.msg);
                  if (res.success) {
                    this.oldModelName = this.form.name
                  }
                  this.queryList();
                  this.$Spin.hide();
                });
              }

            },
          });
        } else {
          this.$Message.error("参数验证错误，请仔细填写表单数据!");
        }
      });



    },
    /*-------------------------导入导出 begin------------------------- */
    //导出全部
    async exportAll() {
      try {
        this.allExportBtnLoading = true;
        let params = this.convertQueryParam();
        await easyComputeModelApi.exportAll(params);
      } catch (e) {
      } finally {
        this.allExportBtnLoading = false;
      }
    },
    //批量导出
    async batchExport() {
      if (!this.validateMainTableSelection()) {
        return;
      }
      this.batchExportBtnLoading = true;
      var ids = this.mainTableSelectArray.map(e => e.id)
      var map = [];
      this.mainTable.data.forEach((e) => {
        if (ids.indexOf(e.id) !== -1) {
          map.push(e);
        }
      })
      this.exportData = map;
      this.$refs.xTable.exportData({ data: map, type: "csv" });
      this.batchExportBtnLoading = false;
      // if (!this.validateMainTableSelection()) {
      //   return;
      // }
      // try {
      //   this.batchExportBtnLoading = true;
      //   await easyComputeModelApi.batchExport(this.mainTableSelectArray.map(e => e.id));
      //   this.$Message.success("导出成功");
      // } catch (e) {
      //   console.log(e);
      //   this.$Message.error("导出成功");
      // } finally {
      //   this.batchExportBtnLoading = false;
      // }
    },
    /*-------------------------导入导出 end------------------------- */
    getDataArray() {
      let params = {
        pageNum: 1,
        pageSize: 100,
        otherCanUse: 1
      };
      vehicleApi.queryVehicle(params).then(result => {
        this.dataArray.vehicle = result.data.list;
      });
      roadApi.queryRoad(params).then(result => {
        this.dataArray.road = result.data.list;
      });
      environmentApi.queryEnvironment(params).then(result => {
        this.dataArray.environment = result.data.list;
      });
      gearboxApi.queryGearbox(params).then(result => {
        this.dataArray.gearbox = result.data.list;
      });
      engineApi.queryEngine(params).then(result => {
        this.dataArray.engine = result.data.list;
      });
      bodyApi.queryBody(params).then(result => {
        this.dataArray.body = result.data.list;
      });
      driveshaftApi.queryDriveshaft(params).then(result => {
        this.dataArray.driveShaft = result.data.list;
      });
      wheelApi.queryWheel(params).then(result => {
        this.dataArray.wheel = result.data.list;
      });
      transaxleApi.queryTransaxle(params).then(result => {
        this.dataArray.transaxle = result.data.list;
      });
    },
    async resetData(e) {
      let params = {
        pageNum: 1,
        pageSize: 100,
        otherCanUse: 1
      };
      switch (e) {
        case 1:
          vehicleApi.queryVehicle(params).then(result => {
            this.dataArray.vehicle = result.data.list;
          });
          break;
        case 2:
          bodyApi.queryBody(params).then(result => {
            this.dataArray.body = result.data.list;
          });

          break;
        case 3:
          roadApi.queryRoad(params).then(result => {
            this.dataArray.road = result.data.list;
          });

          break;
        case 4:
          gearboxApi.queryGearbox(params).then(result => {
            this.dataArray.gearbox = result.data.list;
          });
          break;
        case 5:
          engineApi.queryEngine(params).then(result => {
            this.dataArray.engine = result.data.list;
          });
          break;
        case 6:
          wheelApi.queryWheel(params).then(result => {
            this.dataArray.wheel = result.data.list;
          });

          break;
        case 7:
          transaxleApi.queryTransaxle(params).then(result => {
            this.dataArray.transaxle = result.data.list;
          });
          break;
      }
    },
    cleanVehicle() {
      this.form.roadId = ""
      this.form.generatorId = ""
      this.form.engineId = ""
      this.form.bodyId = ""
      this.form.wheelId = ""
      this.form.transaxleId = ""
      this.cleanRoad();
      this.cleanGearbox();
      this.cleanEngine();
      this.cleanBody();
      this.cleanWheel();
      this.cleanTransaxle();
      this.cleanResult();
      this.form.slope = "";
    },
    cleanRoad() {

      this.form.rollingResistanceCoefficient = ""
      this.form.adhesionCoefficient = ""
    },
    cleanGearbox() {
      this.form.gearboxGear = ""
      this.form.gearboxSpeedRatio = ""
      this.form.gearboxEfficiency = ""

    },
    cleanEngine() {
      this.form.engineSpeed = ""
      this.form.engineTorque = ""
      this.form.enginePower = ""
    },
    cleanBody() {
      this.form.weight = ""
      this.form.windwardArea = ""
      this.form.dragCoefficient = ""

    },
    cleanWheel() {
      this.form.dynamicRollingRadius = ""
    },
    cleanTransaxle(e) {
      this.form.transaxleSpeedRatio = ""
      this.form.transaxleEfficiency = ""

    },
    selectVehicle(e) {
      var data = this.dataArray["vehicle"].find(item => item.id == e);
      this.form.roadId = data.roadId
      this.selectRoad(data.roadId);
      this.form.generatorId = data.gearboxId
      this.selectGearbox(data.gearboxId);
      this.form.engineId = data.engineId
      this.selectEngine(data.engineId);
      this.form.bodyId = data.bodyId
      this.selectBody(data.bodyId);
      this.form.wheelId = data.wheelId
      this.selectWheel(data.wheelId);
      this.form.transaxleId = data.transaxleId
      this.selectTransaxle(data.transaxleId);
    },
    selectRoad(e) {
      var data = this.dataArray["road"].find(item => item.id == e);
      if (data) {
        this.form.rollingResistanceCoefficient = data.rollingResistanceCoefficient
        this.form.adhesionCoefficient = data.adhesionCoefficient
      }

    },
    selectGearbox(e) {
      var data = this.dataArray["gearbox"].find(item => item.id == e); if (data) {
        this.gearboxGear = data.forwardGearNumber ? data.forwardGearNumber : 7
        this.form.gearboxGear = ""
        this.form.gearboxSpeedRatio = ""
        this.form.gearboxEfficiency = ""
      }
    },
    selectEngine(e) {
      var data = this.dataArray["engine"].find(item => item.id == e); if (data) {
        var engineTypeArr = this.engineType[this.form.engineType];
        if (data) {
          this.form.engineSpeed = data[engineTypeArr[0]]
          this.form.engineTorque = data[engineTypeArr[1]]
          this.form.enginePower = data[engineTypeArr[2]]
        }
      }
    },
    selectBody(e) {
      var data = this.dataArray["body"].find(item => item.id == e); if (data) {
        this.form.weight = data.gvw * 1000
        this.form.windwardArea = data.frontalArea
        this.form.dragCoefficient = data.dragCoefficient
      }
    },
    selectWheel(e) {
      var data = this.dataArray["wheel"].find(item => item.id == e); if (data) {
        this.form.dynamicRollingRadius = data.dynamicRollingRadius / 1000
      }
    },
    selectTransaxle(e) {
      var data = this.dataArray["transaxle"].find(item => item.id == e); if (data) {
        this.form.transaxleSpeedRatio = data.mainGearRatio * data.hubGearRatio
        this.form.transaxleEfficiency = data.efficiency
      }
    },
    selectVehicleSn(e) {
      var data = this.dataArray["vehicle"].find(item => item.sn == e);
      if (data) {
        this.form.vehicleId = data.id;
        this.selectVehicle(data.id)
      }

    },
    selectRoadSn(e) {
      var data = this.dataArray["road"].find(item => item.name == e);
      if (data) {
        this.form.roadId = data.id
        this.form.rollingResistanceCoefficient = data.rollingResistanceCoefficient
        this.form.adhesionCoefficient = data.adhesionCoefficient
      }

    },
    selectGearboxSn(e) {
      var data = this.dataArray["gearbox"].find(item => item.sn == e);
      if (data) {
        this.form.generatorId = data.id
        this.gearboxGear = data.forwardGearNumber ? data.forwardGearNumber : 7
      }

    },
    async selectGear(e) {
      if (e && this.form.generatorId) {
        let result = await gearboxSpeedApi.getByGear({ gearboxId: this.form.generatorId, gear: e })
        if (result.data) {
          this.form.gearboxSpeedRatio = parseFloat(result.data.speedRatio)
          this.form.gearboxEfficiency = parseFloat(result.data.efficiency)
        } else {
          this.form.gearboxSpeedRatio = ""
          this.form.gearboxEfficiency = ""
        }
      }
    },
    selectEngineSn(e) {
      var data = this.dataArray["engine"].find(item => item.sn == e); if (data) {
        this.form.engineId = data.id;
        this.form.engineSpeed = data.maxSpeed
        this.form.engineTorque = data.maxTorque
        this.form.enginePower = data.maxPower
      }
    },
    selectBodySn(e) {
      var data = this.dataArray["body"].find(item => item.sn == e); if (data) {
        this.form.bodyId = data.id;
        this.form.weight = data.gvw * 1000
        this.form.windwardArea = data.frontalArea
        this.form.dragCoefficient = data.dragCoefficient
      }
    },
    selectWheelSn(e) {
      var data = this.dataArray["wheel"].find(item => item.sn == e); if (data) {
        this.form.wheelId = data.id;
        this.form.dynamicRollingRadius = data.dynamicRollingRadius / 1000
      }
    },
    selectDriveShaftSn(e) {
      var data = this.dataArray["driveshaft"].find(item => item.sn == e); if (data) {
        this.form.driveshaftId = data.id;
        this.form.transaxleSpeedRatio = data.maxInputSpeed
        this.form.transaxleEfficiency = data.maxInputTorque
      }
    },
    selectTransaxleSn(e) {
      var data = this.dataArray["transaxle"].find(item => item.sn == e);
      if (data) {
        this.form.transaxleId = data.id;
        this.form.transaxleSpeedRatio = data.mainGearRatio * data.hubGearRatio
        this.form.transaxleEfficiency = data.efficiency
      }

    },
    engineTypeChange(e) {
      if (e && this.form.engineId) {
        var engineTypeArr = this.engineType[e];
        var data = this.dataArray["engine"].find(item => item.id == this.form.engineId);
        if (data) {
          this.form.engineSpeed = data[engineTypeArr[0]]
          this.form.engineTorque = data[engineTypeArr[1]]
          this.form.enginePower = data[engineTypeArr[2]]
        } else {
          this.form.engineSpeed = ""
          this.form.engineTorque = ""
          this.form.enginePower = ""
        }
      }
    }
  }
};

</script>
<style>
.flex input {
  width: 100px;
}

.ivu-table table th {
  border: 1px #e1e1e1 solid !important;
  background: #fff !important;
}

.ivu-table table td {
  border-left: none !important;
  border-right: none !important;
  height: 50px !important;
  font-size: 14px !important;
}

::-webkit-scrollbar {
  height: 13px !important;
}
</style>
<style lang="less">
.ivu-row {
  display: flex;
  align-items: center;
}

.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.input-box {
  //   padding-left: 30%;
}

.span {
  width: 100px;
  text-align: left;
}

.box {
  width: 100%;
  height: 600px;
  padding: 30px;
}


.margin0 {
  margin: 0;
}

.easy-computer1 {
  width: 100%;
  height: 100%;
  background: url(../../../assets/images/easy-computer1.jpg) no-repeat;
  background-size: 100% 100%;
}

.easy-computer2 {
  width: 100%;
  height: 90%;
  background: url(../../../assets/images/easy-computer3.jpg) no-repeat;
  background-size: 80% 100%;
  background-position-x: -30px;
  // background-position-y: 30px;
}

.result-input {
  width: 100px;
}

.text-align {
  text-align: left;
}

.list-button:hover {
  color: #2d8cf0;
  cursor: pointer;
}

.button_box {
  padding: 0 10px;
}

.button_flex {
  display: block;
  width: 80%;
  margin: 0 auto 20px;
}

.card-main {
  padding-left: 10px;
  padding-right: 10px;
}

.page-bottom {
  text-align: right;
  padding-right: 20px;
}

.content-box {
  flex: 2000;
  padding: 10px;

}

.button-box-top {
  padding-top: 20px;
}

.row-sty {
  align-items: flex-start;
  display: block
}

.col-sty {
  justify-content: flex-end;
  display: flex;
}

.com-query-page .smart-query-table-page {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}
</style>
